/**   
 * @Title: TestTypeServiceImplementation.java 
 * @Package cn.edu.cdtu.healthserver.service.impl 
 * @Description: TODO 
 * @author  
 * @date 
 * @version V0.0   
 */
package cn.edu.cdtu.healthserver.service.impl;

import java.util.ArrayList;
import java.util.List;

import cn.edu.cdtu.healthserver.dao.TestTypeDao;
import cn.edu.cdtu.healthserver.dao.impl.TestTypeDaoImplementation;
import cn.edu.cdtu.healthserver.domain.TestType;
import cn.edu.cdtu.healthserver.service.TestTypeService;

/** 
 * @ClassName: TestTypeServiceImplementation 
 * @Description: TODO
 * @author 
 * @date 
 *  
 */
public class TestTypeServiceImplementation implements TestTypeService {
	
	private TestTypeDao testTypeDao = new TestTypeDaoImplementation();

	/*
	 * (non-Javadoc)
	 * <p>Title: getTestTypes</p> 
	 * <p>Description: </p> 
	 * @param listAvailable
	 * @return 
	 * @see cn.edu.scu.healthserver.service.TestTypeService#getTestTypes(boolean)
	 */
	@Override
	public List<TestType> getTestTypes(boolean listAvailable) {
		// TODO Auto-generated method stub
		List<TestType> testTypes = testTypeDao.queryALL();
		if(listAvailable){
			return testTypes;
		}
		List<TestType> removeList = new ArrayList<TestType>();
		for(TestType type:testTypes){
			if(0==type.getAvailable()){
				removeList.add(type);
			}
		}
		for(TestType type:removeList){
			testTypes.remove(type);
		}
		return testTypes;
	}

	/* (non-Javadoc)
	 * <p>Title: addTestType</p> 
	 * <p>Description: </p> 
	 * @param testType 
	 * @see cn.edu.scu.healthserver.service.TestTypeService#addTestType(cn.edu.scu.healthserver.domain.TestType)
	 */
	@Override
	public String addTestType(TestType testType) {
		// TODO Auto-generated method stub
		String resultString = null;
		if(testTypeDao.add(testType)){
			resultString = "添加测试类型成功！";
		}else{
			resultString = "添加测试类型失败！";
		}
		return resultString;
	}

	/* (non-Javadoc)
	 * <p>Title: updateTestType</p> 
	 * <p>Description: </p> 
	 * @param testType 
	 * @see cn.edu.scu.healthserver.service.TestTypeService#updateTestType(cn.edu.scu.healthserver.domain.TestType)
	 */
	@Override
	public String updateTestType(TestType testType) {
		// TODO Auto-generated method stub
		String resultString = null;
		if(testTypeDao.update(testType)){
			resultString = "更新测试类型成功！";
		}else{
			resultString = "更新测试类型失败！";
		}
		return resultString;
	}

	/* (non-Javadoc)
	 * <p>Title: setAvailable</p> 
	 * <p>Description: </p> 
	 * @param testType
	 * @param available
	 * @return 
	 * @see cn.edu.scu.healthserver.service.TestTypeService#setAvailable(cn.edu.scu.healthserver.domain.TestType, boolean)
	 */
	@Override
	public String setAvailable(TestType testType, boolean available) {
		// TODO Auto-generated method stub
		String resultString = null;
		if(available){
			testType.setAvailable(1);
			if(testTypeDao.update(testType)){
				resultString = "设置测试类型有效成功！";
			}else{
				resultString = "设置测试类型有效失败！";
			}
		}else{
			testType.setAvailable(0);
			if(testTypeDao.update(testType)){
				resultString = "设置测试类型失效成功！";
			}else{
				resultString = "设置测试类型失效失败！";
			}
		}
		return resultString;
	}

}
